package com.springBoot.controller;

import com.springBoot.entity.RainQuality;
import com.springBoot.service.RainQualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/users")
public class RainQualityController {
    @Autowired
    private RainQualityService rainQualityService;

    //添加跳转
    @GetMapping("/toAdd")
    public String toAdd(){
        return "user/add";
    }

    //查询所有
    @GetMapping
    public String cx(Model model){
        model.addAttribute("cx",rainQualityService.cx());
        return "user/list";
    }
    //添加
    @PostMapping("/add")
    public String add(RainQuality rainQuality){
        rainQualityService.add(rainQuality);
        return "redirect:/users";
    }
    //删除
    @GetMapping("/del/{id}")
    public String del(@PathVariable("id") Integer id){
        rainQualityService.del(id);
        return "redirect:/users";
    }
    //修改
    @PostMapping("/update")
    public String update(RainQuality rainQuality){
        rainQualityService.update(rainQuality);
        return "redirect:/users";
    }
    //根据id查询信息
    @GetMapping("/toUpdate")
    public String update(Integer id,Model model){
        model.addAttribute("user",rainQualityService.get(id));
        return "user/update";
    }
}
